<script setup>
import { ref, onMounted, onUnmounted } from 'vue'

const currentTime = ref('')
const isScrolled = ref(false)
let timer

const updateTime = () => {
  const now = new Date()
  const options = {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hour12: false
  }
  currentTime.value = now.toLocaleString('zh-CN', options)
}

const handleScroll = () => {
  isScrolled.value = window.scrollY > 0
}

onMounted(() => {
  updateTime()
  timer = window.setInterval(updateTime, 1000)
  window.addEventListener('scroll', handleScroll)
})

onUnmounted(() => {
  clearInterval(timer)
  window.removeEventListener('scroll', handleScroll)
})
</script>

<template>
  <header class="header-bar" :class="{ 'scrolled': isScrolled }">
    <div class="header-content">
      <div class="header-left">
        <div class="logo">
          <div class="logo-icon">
            <i class="fas fa-shield-alt"></i>
          </div>
          <span>企业信用监管平台</span>
        </div>
        <div class="current-time">
          <i class="far fa-clock"></i>
          <time>{{ currentTime }}</time>
        </div>
      </div>
      
      <div class="header-right">
        <div class="user-info">
          <div class="avatar">
            <i class="fas fa-user"></i>
          </div>
          <span class="username">管理员</span>
          <i class="fas fa-chevron-down"></i>
        </div>
      </div>
    </div>
  </header>
</template>

<style scoped lang="scss">
.header-bar {
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  &.scrolled {
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    padding: 8px 0;
  }
  
  &::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg,
      rgba(59, 130, 246, 0.1),
      transparent 20%,
      transparent 80%,
      rgba(59, 130, 246, 0.1)
    );
    pointer-events: none;
  }
}

.header-content {
  max-width: 1920px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 48px;
  position: relative;
  z-index: 1;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  
  .logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3B82F6, #1D4ED8);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    
    &::before {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.2),
        transparent
      );
    }
    
    &::after {
      content: '';
      position: absolute;
      inset: -1px;
      background: linear-gradient(
        -45deg,
        transparent,
        rgba(255, 255, 255, 0.15)
      );
      border-radius: inherit;
    }
    
    i {
      color: white;
      font-size: 20px;
      filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
      position: relative;
      z-index: 1;
    }
  }
  
  span {
    color: #E2E8F0;
    font-size: 22px;
    font-weight: 600;
    background: linear-gradient(90deg, #F8FAFC, #CBD5E1);
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  &:hover {
    .logo-icon {
      transform: scale(1.05);
      box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
    }
  }
}

.current-time {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #94A3B8;
  font-size: 15px;
  font-family: 'JetBrains Mono', monospace;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  height: 40px;
  transition: all 0.3s ease;
  
  &:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
  }
  
  i {
    color: #60A5FA;
    animation: pulse 2s infinite;
  }
  
  time {
    letter-spacing: 0.5px;
  }
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  
  .avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #3B82F6, #1D4ED8);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    
    &::before {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.2),
        transparent
      );
    }
    
    i {
      color: white;
      font-size: 16px;
      position: relative;
      z-index: 1;
    }
  }
  
  .username {
    color: #E2E8F0;
    font-size: 14px;
    font-weight: 500;
  }
  
  i.fa-chevron-down {
    color: #64748B;
    font-size: 12px;
    transition: transform 0.3s ease;
  }
  
  &:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
    
    .avatar {
      transform: scale(1.05);
    }
    
    i.fa-chevron-down {
      transform: translateY(2px);
    }
  }
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
  100% {
    opacity: 1;
  }
}

@media (max-width: 1600px) {
  .header-bar {
    padding: 10px 0;
  }
  
  .header-content {
    padding: 0 24px;
  }
  
  .logo {
    .logo-icon {
      width: 36px;
      height: 36px;
      
      i {
        font-size: 18px;
      }
    }
    
    span {
      font-size: 20px;
    }
  }
  
  .current-time {
    font-size: 14px;
    padding: 6px 14px;
    height: 36px;
  }
}

@media (max-width: 1366px) {
  .header-bar {
    padding: 8px 0;
  }
  
  .header-content {
    padding: 0 20px;
  }
  
  .logo {
    .logo-icon {
      width: 32px;
      height: 32px;
      
      i {
        font-size: 16px;
      }
    }
    
    span {
      font-size: 18px;
    }
  }
  
  .current-time {
    font-size: 13px;
    padding: 6px 12px;
    height: 34px;
  }
  
  .user-info {
    padding: 6px 12px;
    
    .avatar {
      width: 28px;
      height: 28px;
      
      i {
        font-size: 14px;
      }
    }
    
    .username {
      font-size: 13px;
    }
  }
}
</style>



